onmessage = function(e) {
    let { linePoint, before, color, range } = e.data
    
    let len = linePoint.length;
    let reduceColor = 255 / range.length;

    for (let i = 0; i < len; i++) {
        let ele = linePoint[i];
        if (before[ele + 3] === 0) continue;
        let beforeArr = before.slice(ele,ele + 3);
        for(let j = 0; j < range.length; j++){
            if(testColor(beforeArr,color,range[j])){
                before[ele + 3] = (before[ele + 3] - reduceColor * j) >= 0 ? (before[ele + 3] - reduceColor * j) : 0;
            }
        }
    }

     /**
   * 颜色对比，接受在一定范围内的颜色
   * @param {Array[3]} current 当前需要判断的颜色值
   * @param {Array[3]} target 给定的颜色值
   * @param {number|Array(2)(3)} range  [min,max][[0.1,0.2,0.3],[0.4,0.5,0.6]] 容错大小 colorVal*(±range) >|< targetVal 
   */
    function testColor(current, target, range) {
        if (Array.isArray(range)) { // 判断是否是二元数组，针对rgb三个颜色值进行调整
            // range = [[0.1,0.2,0.3],[0.4,0.5,0.6]];
            // 对RGB三个颜色的最大容错值和最小容错值进行细化
            for (let i = 0; i < 3; i++) {
                if(target[i] === 0) target[i] = 1
                if (!((1 - range[0][i]) * target[i] <= current[i] && (1 + range[1][i]) * target[i] >= current[i])) return false
            }
        } else {
            for (let i = 0; i < 3; i++) {
                if (!((1 - range) * target[i] <= current[i] && (1 + range) * target[i] >= current[i])) return false;
            }
        }
        return true;
    }

    postMessage({before})
}